﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="NL.ADA.ConfigService.UI._Default"
    Theme="DefaultTheme" MasterPageFile="~/UI.Master" ViewStateEncryptionMode="Always"
    MaintainScrollPositionOnPostback="true" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
<asp:Content ContentPlaceHolderID="TheContentPlaceHolder" runat="server" ID="Content">
    <asp:ScriptManager ID="TheScriptManager" runat="server" EnablePartialRendering="true">
    </asp:ScriptManager>

    <script type="text/javascript">
        var prm = Sys.WebForms.PageRequestManager.getInstance();
        prm.add_beginRequest(beginRequest);
        function beginRequest() {
            prm._scrollPosition = null;
        }
    </script>

    <asp:UpdatePanel runat="server" ID="TheUpdatePanel" OnLoad="UpdatePanel_Load" UpdateMode="Conditional">
        <ContentTemplate>
            <div class="subcontainer">
                <div id="divButtons" class="subcontainerbuttons">
                    <div>
                        <asp:LinkButton ID="AddNewRowButton" runat="server" SkinID="AddNewConfigButtonSkin"
                            OnClick="AddNewRowButton_Click" />
                    </div>
                    <div>
                        <asp:LinkButton ID="AddApplicationButton" runat="server" SkinID="AddNewApplicationButtonSkin"
                            OnClick="AddNewApplicationButton_Click" />
                    </div>
                </div>
                <div id="divFilter" class="subcontainerfilter">
                    <div>
                        Application Filter
                        <asp:DropDownList ID="ApplicationDropDownList" runat="server" DataSourceID="ApplicationDataSource"
                            DataTextField="AppCode" DataValueField="Id" AutoPostBack="True" OnDataBound="ApplicationDropDownList_DataBound"
                            OnSelectedIndexChanged="ApplicationDropDownList_SelectedIndexChanged">
                        </asp:DropDownList>
                    </div>
                    <div>
                        Mode Filter
                        <asp:RadioButtonList ID="ModeRadioButtonList" DataSourceID="ModeDataSource" DataTextField="Name"
                            DataValueField="id" runat="server" RepeatDirection="Horizontal" OnDataBound="ModeRadioButtonList_DataBound" AutoPostBack="true">
                        </asp:RadioButtonList>
                    </div>
                </div>
            </div>
            <div id="divGridView" class="gridview">
                <asp:HiddenField ID="InsertedRowDataKeyHiddenField" runat="server" />
                <asp:HiddenField ID="InsertModeHiddenField" runat="server" Value="false" />
                <asp:GridView ID="TheGridView" runat="server" DataSourceID="TheDataSource" AutoGenerateColumns="False"
                    CellPadding="4" ForeColor="#333333" GridLines="None" DataKeyNames="ConfigId"
                    Height="347px" Width="100%" OnRowCommand="RowCommand">
                    <RowStyle Height="30" BackColor="#F7F6F3" ForeColor="#333333" />
                    <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                    <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
                    <SelectedRowStyle Height="30" BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
                    <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                    <EditRowStyle Height="30" BackColor="#999999" />
                    <AlternatingRowStyle Height="30" BackColor="White" ForeColor="#284775" />
                    <Columns>
                        <asp:BoundField DataField="ConfigId" Visible="false" />
                        <asp:TemplateField>
                            <HeaderTemplate>
                                <asp:Label ID="ApplicationHeaderLabel" runat="server" Text="Application" />
                            </HeaderTemplate>
                            <ItemTemplate>
                                <asp:Label ID="ApplicationLabel" runat="server" Text='<%#Eval("ApplicationCode") %>' />
                            </ItemTemplate>
                            <EditItemTemplate>
                                <asp:DropDownList ID="ApplicationCellDropDownList" runat="server" DataSourceID="ApplicationDataSource"
                                    DataTextField="AppCode" DataValueField="Id" SelectedValue='<%# Bind("ApplicationId") %>'>
                                </asp:DropDownList>
                            </EditItemTemplate>
                        </asp:TemplateField>
                        <asp:BoundField DataField="Key" Visible="true" HeaderText="Key" SortExpression="Key" />
                        <asp:BoundField DataField="Value" HeaderText="Value" SortExpression="Value" />
                        <asp:TemplateField>
                            <HeaderTemplate>
                                <asp:Label ID="ConfigTypeHeaderLabel" runat="server" Text="Type" />
                            </HeaderTemplate>
                            <ItemTemplate>
                                <asp:Label ID="ConfigTypeLabel" runat="server" Text='<%#Eval("ConfigTypeName") %>' />
                            </ItemTemplate>
                            <EditItemTemplate>
                                <asp:DropDownList ID="ConfigTypeCellDropDownList" runat="server" DataSourceID="ConfigTypeDataSource"
                                    DataTextField="Name" DataValueField="Id" SelectedValue='<%# Bind("ConfigTypeId") %>'>
                                </asp:DropDownList>
                            </EditItemTemplate>
                        </asp:TemplateField>
                        <asp:BoundField ReadOnly="true" DataField="ApplicationCode" HeaderText="Application"
                            SortExpression="ApplicationCode" />
                        <asp:TemplateField>
                            <HeaderTemplate>
                                <asp:Label ID="ModeHeaderLabel" runat="server" Text="Mode" />
                            </HeaderTemplate>
                            <ItemTemplate>
                                <asp:Label ID="ModeLabel" runat="server" Text='<%#Eval("ModeName") %>' />
                            </ItemTemplate>
                            <EditItemTemplate>
                                <asp:DropDownList ID="ModeCellDropDownList" runat="server" DataSourceID="ModeDataSource"
                                    DataTextField="Name" DataValueField="Id" SelectedValue='<%# Bind("ModeId") %>'>
                                </asp:DropDownList>
                            </EditItemTemplate>
                        </asp:TemplateField>
                        <asp:CommandField ShowEditButton="True" ShowDeleteButton="True" />
                    </Columns>
                </asp:GridView>
            </div>
            <asp:Panel runat="server" ID="TheFormPanel" CssClass="applicationformpanel">
                <asp:Panel ID="TheFormInnerPanel" runat="server">
                    <asp:FormView ID="FormView1" runat="server" DataSourceID="ApplicationEditDataSource"
                        CellPadding="4" OnItemCommand="FormViewItemCommand" Height="259px" Width="385px"
                        ForeColor="#333333" OnItemInserted="FormView_ItemInserted">
                        <FooterStyle BackColor="#5D7B9D" ForeColor="White" Font-Bold="True" />
                        <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
                        <HeaderTemplate>
                            <asp:LinkButton runat="server" Text="x" ID="CancelLinkButton" OnClick="CancelLinkButtonClick"
                                SkinID="CancelLinkButtonSkin" />
                        </HeaderTemplate>
                        <EditItemTemplate>
                            <table id="EditItemFormTable">
                                <tr>
                                    <td>
                                        AppCode:
                                    </td>
                                    <td>
                                        <asp:TextBox ID="AppCodeTextBox" runat="server" Text='<%# Bind("AppCode") %>' Height="22px"
                                            Width="278px" />
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                        Description:
                                    </td>
                                    <td>
                                        <asp:TextBox ID="DescriptionTextBox" runat="server" Height="60px" Width="278px" TextMode="MultiLine"
                                            Text='<%# Bind("Description") %>' />
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                    </td>
                                    <td>
                                        <asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True" CommandName="Update"
                                            Text="Update" />
                                        &nbsp;<asp:LinkButton ID="UpdateCancelButton" runat="server" CausesValidation="False"
                                            CommandName="Cancel" Text="Cancel" />
                                    </td>
                                </tr>
                            </table>
                        </EditItemTemplate>
                        <InsertItemTemplate>
                            <table id="InsertItemFormTable" style="height: 185px; width: 374px">
                                <tr>
                                    <td>
                                        AppCode:
                                    </td>
                                    <td>
                                        <asp:TextBox ID="AppCodeTextBox" runat="server" Text='<%# Bind("AppCode") %>' Height="22px"
                                            Width="278px" />
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                        Description:
                                    </td>
                                    <td>
                                        <asp:TextBox ID="DescriptionTextBox" runat="server" Width="278px" Height="60px" TextMode="MultiLine"
                                            Text='<%# Bind("Description") %>' />
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                    </td>
                                    <td>
                                        <asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True" CommandName="Insert"
                                            Text="Insert" />
                                        &nbsp;<asp:LinkButton ID="InsertCancelButton" runat="server" CausesValidation="False"
                                            CommandName="Cancel" Text="Cancel" />
                                    </td>
                                </tr>
                        </InsertItemTemplate>
                        <ItemTemplate>
                            <table id="itemFormTable">
                                <tr>
                                    <td>
                                        AppCode:
                                    </td>
                                    <td>
                                        <asp:Label ID="AppCodeLabel" runat="server" Text='<%# Bind("AppCode") %>' />
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                        Description:
                                    </td>
                                    <td style="width: 322px">
                                        <asp:Label ID="DescriptionLabel" runat="server" Text='<%# Bind("Description") %>' />
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                    </td>
                                    <td style="width: 322px">
                                        <asp:LinkButton ID="EditButton" runat="server" CausesValidation="False" CommandName="Edit"
                                            Text="Edit" />
                                        &nbsp;<asp:LinkButton ID="NewButton" runat="server" CausesValidation="False" CommandName="New"
                                            Text="New" />
                                    </td>
                                </tr>
                            </table>
                        </ItemTemplate>
                        <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
                        <HeaderStyle HorizontalAlign="Right" VerticalAlign="Top" BackColor="#5D7B9D" Font-Bold="True"
                            ForeColor="White" />
                        <EditRowStyle BackColor="#999999" />
                    </asp:FormView>
                </asp:Panel>
            </asp:Panel>
        </ContentTemplate>
    </asp:UpdatePanel>
    <asp:ObjectDataSource ID="ApplicationEditDataSource" runat="server" InsertMethod="InsertApplication"
        SelectMethod="SelectApplicationById" TypeName="NL.ADA.UI.Gateway" UpdateMethod="UpdateApplication">
        <UpdateParameters>
            <asp:Parameter Name="id" Type="Int32" />
            <asp:Parameter Name="appCode" Type="String" />
            <asp:Parameter Name="description" Type="String" />
        </UpdateParameters>
        <SelectParameters>
            <asp:Parameter DefaultValue="1" Name="id" Type="Int32" />
        </SelectParameters>
        <InsertParameters>
            <asp:Parameter Name="appCode" Type="String" />
            <asp:Parameter Name="description" Type="String" />
        </InsertParameters>
    </asp:ObjectDataSource>
    <div id="divMessages" class="messages">
        <asp:ValidationSummary ID="ConfigValidationSummary" runat="server" ShowMessageBox="true" />
    </div>
    <asp:ObjectDataSource ID="ModeDataSource" runat="server" TypeName="NL.ADA.UI.Gateway"
        SelectMethod="GetModes"></asp:ObjectDataSource>
    <asp:ObjectDataSource ID="ConfigTypeDataSource" runat="server" TypeName="NL.ADA.UI.Gateway"
        SelectMethod="GetConfigTypes"></asp:ObjectDataSource>
    <asp:ObjectDataSource ID="ApplicationDataSource" runat="server" TypeName="NL.ADA.UI.Gateway"
        SelectMethod="GetAllApplications"></asp:ObjectDataSource>
    <asp:ObjectDataSource ID="TheDataSource" runat="server" TypeName="NL.ADA.UI.Gateway"
        SelectMethod="GetAllConfigs" UpdateMethod="UpdateConfig" DeleteMethod="Delete">
        <DeleteParameters>
            <asp:Parameter Name="configId" Type="Int32" />
        </DeleteParameters>
        <UpdateParameters>
            <asp:Parameter Name="configId" Type="Int32" />
            <asp:Parameter Name="modeId" Type="Int32" />
            <asp:Parameter Name="key" Type="String" />
            <asp:Parameter Name="value" Type="String" />
            <asp:Parameter Name="applicationId" Type="Int32" />
            <asp:Parameter Name="configTypeName" Type="String" />
            <asp:Parameter Name="configTypeId" Type="Int32" />
        </UpdateParameters>
        <SelectParameters>
            <asp:ControlParameter ControlID="ApplicationDropDownList" Type="Int32" PropertyName="SelectedValue"
                Name="appId" />
            <asp:ControlParameter ControlID="ModeRadioButtonList" Type="Int32" PropertyName="SelectedValue"
                Name="modeId" />
        </SelectParameters>
        <FilterParameters>
        </FilterParameters>
    </asp:ObjectDataSource>
</asp:Content>
